package com.hanlink.dsp.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.util.DisplayMetrics;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

import com.qztech.sdk.R;


/**
 * Created by zhb on 2015-11-23.
 */
public class AskAlertDialog extends Dialog {

    private TextView textView;
    private Button btnSure;
    private Button btnCancel;

    public interface OnComfirmClickListener {
        void onClick(AskAlertDialog dialog);
    }

    private OnComfirmClickListener mOnClickListener;

    public AskAlertDialog(Context context, String text, boolean cancelable, OnComfirmClickListener onClickListener) {
        super(context, R.style.dialog);
        mOnClickListener = onClickListener;
        setCancelable(cancelable);
        initView();
        setMessage(text);
    }

    private void initView() {
        WindowManager wm = (WindowManager) getContext().getSystemService(
                Context.WINDOW_SERVICE);
        DisplayMetrics outMetrics = new DisplayMetrics();
        wm.getDefaultDisplay().getMetrics(outMetrics);
//        setContentView(getLayoutInflater().inflate(R.layout.dialog_ask, null), new ViewGroup.LayoutParams((int) (outMetrics.widthPixels * 0.6), ViewGroup.LayoutParams.WRAP_CONTENT));
        setContentView(com.hanlink.res.R.layout.dialog_ask);
        this.textView = findViewById(com.hanlink.res.R.id.message);
        btnSure = findViewById(com.hanlink.res.R.id.btnSure);
        btnCancel = findViewById(com.hanlink.res.R.id.btnCancel);
        setCanceledOnTouchOutside(true);
        btnSure.setOnClickListener(v -> {
            mOnClickListener.onClick(this);
        });
        btnCancel.setOnClickListener(v -> {
            dismiss();
        });
    }

    @Override
    public void show() {
        super.show();
    }

    @Override
    public void dismiss() {
        super.dismiss();
    }

    public void setMessage(int resId) {
        textView.setText(getContext().getString(resId));
    }

    public void setMessage(String text) {
        textView.setText(text);
    }

}
